﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;
using Nvigorate.Aspect;
using Nvigorate.Data.Query;
using Nvigorate.Relational;
using Nvigorate.Relational.Mapping.Fluent;
using Nvigorate.Relational.State;

namespace Nvigorate.TestObjects
{

    [AttributeUsage(AttributeTargets.Property)]
    public class QueryableAttribute : Attribute
    {
    }

//  [DatabaseLazyLoadAspect(RepositoryName = "simple")]
    [StateTrackingAspect]
    public class Person : StateTracking
    {
        public IList<Address> Addresses { get; set; }
        [Queryable] public string FirstName { get; set; }
        [Queryable] public string LastName { get; set; }
        [Queryable] public DateTime DateOfBirth { get; set; }
        [Queryable] public string SocialSecurity { get; set; }
        public List<Vehicle> Vehicles{ get; set; }
        public PhoneNumber HomePhone { get; set; }

        public Person()
        {
            DateOfBirth = SqlDateTime.MinValue.Value;
        }
    }

    public class terd : ITrackState
    {
        public event PropertyChangedEventHandler PropertyChanged;
        public event PropertyChangingEventHandler PropertyChanging;
        public bool Deserializing
        {
            get { throw new NotImplementedException(); }
            set { throw new NotImplementedException(); }
        }

        public IPersistenceState InstanceState
        {
            get { throw new NotImplementedException(); }
        }

        public void RaisePropertyChanged(string property)
        {
            throw new NotImplementedException();
        }

        public void RaisePropertyChanging(string property)
        {
            throw new NotImplementedException();
        }
    }

    public class PersonMap : FluentMap<Person>
    {
        public PersonMap()
        {
            RepositoryName = "simple";

            var person = MapTable();
            person.Assign(p => p.SocialSecurity).AsKey();
            person.Assign(p => p.FirstName);
            person.Assign(p => p.LastName);
            person.Assign(p => p.DateOfBirth);

            MapChildren(p => p.Vehicles)
                .ForeignKey(p => p.SocialSecurity, v => v.OwnerSocial);
        }
    }
}
